package offer;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Author Elephas
 * @Date 2022/1/28
 **/
@FunctionalInterface
public interface Intersection {
    int[] intersection(int[] nums1,int[] nums2);
}
class IntersectionImpl1 implements Intersection{

    @Override
    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new LinkedHashSet<>();
        Set<Integer> set2 = new LinkedHashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            set2.add(nums2[i]);
        }
        int[] ans = set1.stream().filter(element -> set2.contains(element)).mapToInt(Integer::valueOf).toArray();
        return ans;
    }
}
